// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import httpRequest from '@/utils/httpRequest'
import VueCookie from 'vue-cookie'
import './assets/css/global.css' // 导入全局样式表
import './assets/font/iconfont.css' // 图标字体
import { Indicator, Toast, InfiniteScroll, Spinner } from 'mint-ui'

import fastClick from 'fastclick'
// element-ui
import {
  Input,
  Checkbox,
  Button,
  Form,
  FormItem,
  Row,
  Col,
  Container,
  Header,
  Aside,
  Main
} from 'element-ui'

// import pageination from 'vue_pageination'    //分页
Vue.$toast = Vue.prototype.$toast = Toast
Vue.$indicator = Vue.prototype.$indicator = Indicator

Vue.component(Toast.name, Toast)
Vue.use(InfiniteScroll)
Vue.component(Spinner.name, Spinner)

Vue.use(Input)
Vue.use(Checkbox)
Vue.use(Button)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Row)
Vue.use(Col)
Vue.use(Container)
Vue.use(Header)
Vue.use(Aside)
Vue.use(Main)

fastClick.attach(document.body)

// Vue.use(pageination)

// Vue.config.productionTip = false
Vue.use(VueCookie)

Vue.prototype.$http = axios
Vue.prototype.$http = httpRequest

// 使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const token = Vue.cookie.get('token')
  if (!token) return next('/login')

  next()
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
